<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>赋予权限</title>
	<meta name="decorator" content="blank"/>
	<%@include file="/WEB-INF/views/include/treeview.jsp" %>
	<script type="text/javascript">
	
		
		// 初始化
		$(document).ready(function(){
			var setting = {check:{enable:true,nocheckInherit:true},view:{selectedMulti:false},
					data:{simpleData:{enable:true}},callback:{
						beforeCheck:function(){
							return false;
						}
					}
			};
			
			// 前
			var zNodes1=[
					<c:forEach items="${menuList}" var="menu">{id:"${menu.id}", pId:"${not empty menu.parent.id?menu.parent.id:0}", name:"${not empty menu.parent.id?menu.name:'权限列表'}"},
		            </c:forEach>];
			// 后
			var zNodes2=[
					<c:forEach items="${menuList}" var="menu">{id:"${menu.id}", pId:"${not empty menu.parent.id?menu.parent.id:0}", name:"${not empty menu.parent.id?menu.name:'权限列表'}"},
		            </c:forEach>];
			// 初始化树结构
			var beforeTree = $.fn.zTree.init($("#beforeTree"), setting, zNodes1);
			// 不选择父节点
			beforeTree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
			// 初始化树结构
			var afterTree = $.fn.zTree.init($("#afterTree"), setting, zNodes2);
			// 不选择父节点
			afterTree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
			// 默认选择节点
			var ids1 = "${oldIds}".split(",");
			for(var i=0; i<ids1.length; i++) {
				var node = beforeTree.getNodeByParam("id", ids1[i]);
				try{beforeTree.checkNode(node, true, false);}catch(e){}
			}
			// 默认展开全部节点
			beforeTree.expandAll(true);
			// 默认选择节点
			var ids2 = "${newIds}".split(",");
			for(var i=0; i<ids2.length; i++) {
				var node = afterTree.getNodeByParam("id", ids2[i]);
				try{afterTree.checkNode(node, true, false);}catch(e){}
			}
			// 默认展开全部节点
			afterTree.expandAll(true);
			//全部禁用
		});
	</script>
</head>
<body>
	<div id="assignRole" class="row-fluid span12">
		<div class="span3">
			<p>授权前：</p>
			<div id="beforeTree" class="ztree"></div>
		</div>
		<div class="span3" style="margin-left: 180px;padding-left:16px;border-left: 1px solid #A8A8A8;">
			<p>授权后：</p>
			<div id="afterTree" class="ztree"></div>
		</div>
	</div>
</body>
</html>
